import {CHAT_LIST,READ_MSG,READ_CHAt} from '../constant' 
const init={
    chatMsgs:[],
    users:[]
}
export  function chatmsg (prestate=init,action){
    const {type,data}=action
    switch(type){
        case CHAT_LIST:
            return {...data}
        case READ_MSG:
            return {chatMsgs:[...prestate.chatMsgs,data],users:{...prestate.users}}
        case READ_CHAt:
            const {to,from}=action.data
            console.log(to,from)
            prestate.chatMsgs.forEach((item)=>{
                if(to===item.to&&from===item.from&&!item.read){
                    item.read=true
                    console.log('y已读')
                }
            })
            console.log({chatMsgs:[...prestate.chatMsgs],users:{...prestate.users}},'ss')
            return {chatMsgs:[...prestate.chatMsgs],users:{...prestate.users}}
        default :
            return  prestate
    }
}